<?php

Yii::import('common.models._base.BaseClassVenue');

class ClassVenue extends BaseClassVenue {

    public static function model($className = __CLASS__) {
        return parent::model($className);
    }

    public function rules() {
        return array(
            array('venue_locality,country_id, city_id, state_id, name, address_line1, zip_code', 'required'),
            array('name', 'type', 'type' => 'array', 'allowEmpty' => false),
            array('address_line1,country_id,city_id,state_id,zip_code', 'type', 'type' => 'array', 'allowEmpty' => false),
            array('status, country_id, city_id, state_id, zip_code', 'numerical', 'integerOnly' => true),
        );
    }

    public function attributeLabels() {
        return array(
            'id' => Yii::t('app', 'ID'),
            'name' => Yii::t('app', 'Name'),
            'address_line1' => Yii::t('app', 'Address Line1'),
            'address_line2' => Yii::t('app', 'Address Line2'),
            'venue_locality' => Yii::t('app', 'Locality'),
            'zip_code' => Yii::t('app', 'Zip Code'),
            'status' => Yii::t('app', 'Status'),
            'create_time' => Yii::t('app', 'Create Time'),
            'update_time' => Yii::t('app', 'Update Time'),
            'country_id' => Yii::t('app', 'Country'),
            'city_id' => Yii::t('app', 'City'),
            'state_id' => Yii::t('app', 'State'),
            'users_id' => null,
            'backend_user_id' => null,
            'classBatches' => null,
            'city' => null,
            'country' => null,
            'state' => null,
            'users' => null,
            'backendUser' => null,
            'classWithVenues' => null,
            'courseBatches' => null,
            'courseWithVenues' => null,
        );
    }

    public static function getLocationNameByVenueId($getVenues) {
        $vanueName = '';
        foreach ($getVenues as $getVenues) {
            $vanueName.=$getVenues->classVenue->venue_locality . ' , ';
        }
        $venueSname = substr($vanueName, 0, -2);
        return (strlen($venueSname) > 15) ? substr($venueSname, 0, 25) . ' ..' : substr($venueSname, 0, 18);
    }

    public static function getLocationNameBycourseVenueId($getVenues) {
        $vanueName = '';
        foreach ($getVenues as $getVenues) {
            $vanueName.=$getVenues->courseVenue->venue_locality . ' , ';
        }
        $venueSname = substr($vanueName, 0, -2);
        return (strlen($venueSname) > 15) ? substr($venueSname, 0, 25) . ' ..' : substr($venueSname, 0, 18);
    }

    public static function getVenueAddressVyClassCoursebatchId($type, $batchId) {
        $classVenue = '';
        if ($type != 'class') {
            $venueId = CourseBatche::model()->findByPk($batchId);
            $venueId = !empty($venueId) ? $venueId->course_venue_id : '';
        } else {
            $venueId = ClassBatch::model()->findByPk($batchId);
            $venueId = !empty($venueId) ? $venueId->class_venue_id : '';
        }
        $classVenue = ClassVenue::model()->findByPk($venueId);
        if (!empty($classVenue)) {
            $classVenue = '<div>Venue Name : ' . $classVenue->name . '</br>Venue Address : ' . $classVenue->address_line1 . ' ' . $classVenue->address_line2 . '</br>Venue Area : ' . $classVenue->venue_locality . '</br>
            ' . $classVenue->city->city_name . ' ' . $classVenue->state->name . ' ' . $classVenue->country->name . '</br>
                ' . $classVenue->zip_code . '</div>';
            return $classVenue;
        }
    }

}
